<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Queue;
use app\common\model\Amap;
use EasyWeChat\Factory;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        exit();die;
        $list = Amap::all(['level'=>2,'id'=>['gt',2243]])->toArray();
        foreach ($list as $value){
            $location = getLocationByName($value['name'].'政府');
            Amap::update(['lng'=>$location['lng'],'lat'=>$location['lat']],['id'=>$value['id']]);
        }
        halt($list);




        return $this->view->fetch();
    }

    public function qrcode()
    {
        $wechat = config('Wechat');
        // 商铺ID
        $shop_id = input('shop_id');
        $app = Factory::miniProgram($wechat);
        $response = $app->app_code->getUnlimit("&sid={1}",['page'=>"pages/member/apply",'width'=>440]);
        halt($response);
        $path = "uploads/mini/qrcode/shop_invite/com_qrcode";
        if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
            $filename = $response->saveAs($path, 'appcode.png');
        }
        var_dump($filename);


    }



    //随机生成字符串
    function createNonceStr($length = 8) {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $str = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        return "z".$str;
    }

    function arithmetic($arr){
        var_dump($arr);
        //按照首字母大小写顺序排序
        ksort($arr,SORT_STRING);
        //拼接成字符串
        $str = implode($arr);
        //进行加密
        $signature = sha1($str);
        $signature = md5($signature);
        //转换成大写
        $signature = strtoupper($signature);
        return $signature;
    }

    public function test(){
        
        Queue::push(\app\job\Message::class,[
            'member_id'=>'5761',
            'template_id'=>config('wechat_gzh')['gzh_template']['daichuligongdan'],
            'data'=>[
                'thing41'=>"余额不足，请及时申请充值",
                'thing14'=>"测试店铺",
                'time15'=>date('Y-m-d H:i'),
                'short_thing5'=>"待申请"
            ]
        ],'message');
        
        exit();
    }

}
